# 采集地址 https://wizardforcel.gitbooks.io/java8-tutorials/content/index.html

# 依赖使用的URL https://www.cnblogs.com/linzenews/p/6972192.html
#直接写入文件报错解决方式
#https://stackoverflow.com/questions/33054527/python-3-5-typeerror-a-bytes-like-object-is-required-not-str-when-writing-t
# coding:utf-8
import pdfkit
import os

osfiles = os.listdir("D://PDF//")



def save_pdf(htmls):
    """
    把所有html文件转换成pdf文件
    """
    # options = {
    #     'page-size': 'Letter',
    #     'encoding': "UTF-8",
    #     'custom-header': [
    #         ('Accept-Encoding', 'gzip')
    #     ]
    # }

    pdfkit.from_file(["D://PDF//Java 8 lambda 表达式10个示例.html","d://PDF//Java 8 Lambda 表达式增强版 Comparator 和排序.html"], "D://PDF//PDF.pdf")


# save_pdf(osfiles)

options = {
    'page-size': 'Letter',
    'margin-top': '0.75in',
    'margin-right': '0.75in',
    'margin-bottom': '0.75in',
    'margin-left': '0.75in',
    'encoding': "UTF-8",
    'custom-header' : [
        ('Accept-Encoding', 'gzip')
    ],
    'cookie': [
        ('cookie-name1', 'cookie-value1'),
        ('cookie-name2', 'cookie-value2'),
    ],
    'no-outline': None
}

pdfkit.from_url('http://google.com', 'out.pdf', options=options)